local extension = Package:new("tang_ld")
extension.extensionName = "new_heg_diy_my"
extension.game_modes_whitelist = { "tang_heg_mode" }

extension:loadSkillSkelsByPath("./packages/new_heg_diy_my/pkg/tang_ld/skills")

Fk:loadTranslationTable{
  ["tang_ld"] = "凌烟绘卷",
}


local lijing = General(extension, "wk_heg__lijing", "tang", 4)
lijing.hidden = true
lijing:addSkills{"wk_heg__talu"}
Fk:loadTranslationTable{
  ["wk_heg__lijing"] = "李靖",
  ["#wk_heg__lijing"] = "",
  ["designer:wk_heg__lijing"] = "教父",
  ["illustrator:wk_heg__lijing"] = "",

  ["~wk_heg__lijing"] = "",
}

local sudingfang = General(extension, "wk_heg__sudingfang", "tang", 4)
sudingfang.hidden = true
sudingfang:addSkills{"wk_heg__cuixi", "wk_heg__changshe"}
Fk:loadTranslationTable{
  ["wk_heg__sudingfang"] = "苏定方",
  ["#wk_heg__sudingfang"] = "",
  ["designer:wk_heg__sudingfang"] = "祭祀",
  ["illustrator:wk_heg__sudingfang"] = "",

  ["~wk_heg__sudingfang"] = "",
}

local libai = General(extension, "wk_heg__libai", "tang", 4)
libai.deputyMaxHpAdjustedValue = -1
libai.hidden = true
libai:addSkills{"wk_heg__jiuge", "wk_heg__jianxing", "wk_heg__shiyin"}
Fk:loadTranslationTable{
  ["wk_heg__libai"] = "李白",
  ["#wk_heg__libai"] = "",
  ["designer:wk_heg__libai"] = "静谦",
  ["illustrator:wk_heg__libai"] = "",

  ["~wk_heg__libai"] = "",
}

local lilinfu = General(extension, "wk_heg__lilinfu", "tang", 3)
lilinfu.hidden = true
lilinfu:addSkills{"wk_heg__nongzhang", "wk_heg__mijian"}
Fk:loadTranslationTable{
  ["wk_heg__lilinfu"] = "李林甫",
  ["#wk_heg__lilinfu"] = "",
  ["designer:wk_heg__lilinfu"] = "教父",
  ["illustrator:wk_heg__lilinfu"] = "",

  ["~wk_heg__lilinfu"] = "",
}

local weizheng = General(extension, "wk_heg__weizheng", "tang", 3)
weizheng.hidden = true
weizheng:addSkills{"wk_heg__zhihua", "wk_heg__lianjian", "wk_heg__zhengdian"}
Fk:loadTranslationTable{
  ["wk_heg__weizheng"] = "魏徵",
  ["#wk_heg__weizheng"] = "",
  ["designer:wk_heg__weizheng"] = "教父",
  ["illustrator:wk_heg__weizheng"] = "",

  ["~wk_heg__weizheng"] = "",
}

-- local yuantiangang = General(extension, "wk_heg__yuantiangang", "tang", 3)
-- local xiangshu = fk.CreateTriggerSkill{
--   name = "wk_heg__xiangshu",
--   events = {fk.TargetSpecified},
--   can_trigger = function (self, event, target, player, data)
--     if player:hasSkill(self) and player == target and player.phase == Player.Play then
--       local logic = player.room.logic
--       local use_event = logic:getCurrentEvent()
--       local mark_name = "wk_heg__xiangshu-record-phase"
--       local mark = player:getMark(mark_name)
--       if mark == 0 then
--         logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
--           local last_use = e.data[1]
--           if last_use.from == player.id then
--             mark = e.id
--             player.room:setPlayerMark(player, mark_name, mark)
--             return true
--           end
--           return false
--         end, Player.HistoryPhase)
--       end
--       if mark == use_event.id then
--         return #AimGroup:getAllTargets(data.tos) == 1 and not player.room:getPlayerById(AimGroup:getAllTargets(data.tos)[1]):isKongcheng()
--       end
--     end
--   end,
--   on_use = function (self, event, target, player, data)
--     local room = player.room
--     local to = room:getPlayerById(AimGroup:getAllTargets(data.tos)[1])
--     local cards = to:getCardIds("h")
--     to:showCards(cards)
--     room:animDelay(2)
--     if data.card.suit == Card.NoSuit or not H.compareKingdomWith(player, to) or player:getMark("@@wk_heg__xiangshu_transform") > 0 then return end
--     if table.find(cards, function (cid)
--       return Fk:getCardById(cid).suit == data.card.suit
--     end) then return end
--     if room:askForChoice(player, {"wk_heg__xiangshu_transform::" .. to.id, "Cancel"}, self.name) ~= "Cancel"
--       and room:askForChoice(to, {"transform_deputy", "Cancel"}, self.name) ~= "Cancel" then
--       room:setPlayerMark(player, "@@wk_heg__xiangshu_transform", 1)
--       H.transformGeneral(room, to)
--     end
--   end,
-- }
-- local mingjie = fk.CreateTriggerSkill{
--   name = "wk_heg__mingjie",
--   anim_type = "support",
--   events = {fk.EventPhaseStart},
--   can_trigger = function (self, event, target, player, data)
--     return player:hasSkill(self) and player == target and player.phase == Player.Finish and not player:isKongcheng()
--   end,
--   on_use = function (self, event, target, player, data)
--     local room = player.room
--     local cards = player:getCardIds("h")
--     room:askForYiji(player, cards, room:getOtherPlayers(player, false), self.name, #cards, #cards, "#wk_heg__mingjie-yiji")
--     room:addPlayerMark(player, "@@wk_heg__mingjie")
--   end,

--   refresh_events = {fk.TurnStart},
--   can_refresh = function (self, event, target, player, data)
--     return player == target and player:getMark("@@wk_heg__mingjie") > 0
--   end,
--   on_refresh = function (self, event, target, player, data)
--     player.room:setPlayerMark(player, "@@wk_heg__mingjie", 0)
--   end,
-- }
-- local mingjie_delay = fk.CreateTriggerSkill{
--   name = "#wk_heg__mingjie_delay",
--   anim_type = "drawcard",
--   frequency = Skill.Compulsory,
--   events = {fk.EnterDying},
--   can_trigger = function(self, event, target, player, data)
--     if player == target and player:getMark("@@wk_heg__mingjie") > 0 then
--       local logic = player.room.logic
--       local dying_event = logic:getCurrentEvent()
--       local mark_name = "wk_heg__mingjie_delay-record-turn"
--       local mark = player:getMark(mark_name)
--       if mark == 0 then
--         logic:getEventsOfScope(GameEvent.Dying, 1, function (e)
--           local last_dying = e.data[1]
--           if last_dying.who == player.id then
--             mark = e.id
--             player.room:setPlayerMark(player, mark_name, mark)
--             return true
--           end
--           return false
--         end, Player.HistoryTurn)
--       end
--       if mark == dying_event.id then
--         return true
--       end
--     end
--   end,
--   on_use = function(self, event, target, player, data)
--     player:drawCards(2, self.name)
--   end,
-- }
-- mingjie:addRelatedSkill(mingjie_delay)
-- yuantiangang:addSkill(xiangshu)
-- yuantiangang:addSkill(mingjie)
-- Fk:loadTranslationTable{
--   ["wk_heg__yuantiangang"] = "袁天罡",
--   ["#wk_heg__yuantiangang"] = "",
--   ["designer:wk_heg__yuantiangang"] = "尤提姆",
--   ["illustrator:wk_heg__yuantiangang"] = "",
  
--   ["wk_heg__xiangshu"] = "相术",
--   [":wk_heg__xiangshu"] = "当你于出牌阶段内首次使用牌指定唯一目标后，你可以令其展示所有手牌，若与你使用的此牌花色均不相同且其与你势力相同，你可以令其选择是否变更。",
--   ["wk_heg__mingjie"] = "命诫",
--   [":wk_heg__mingjie"] = "结束阶段，你可以将所有手牌分配给任意名其他角色，若如此做，直至你的下个回合开始，当你于每回合首次进入濒死状态时，你摸两张牌。",
--   ["wk_heg__xiangshu_transform"] = "令%dest选择是否变更副将",
--   ["@@wk_heg__xiangshu_transform"] = "相术 已变更",
--   ["#wk_heg__mingjie-yiji"] = "命诫：将所有手牌分配给其他角色",
--   ["@@wk_heg__mingjie"] = "命诫",
--   ["#wk_heg__mingjie_delay"] = "命诫",

--   ["~wk_heg__yuantiangang"] = ""
-- }

-- local zhangsunwuji = General(extension, "wk_heg__zhangsunwuji", "tang", 4)
-- local xingbian = fk.CreateTriggerSkill{
--   name = "wk_heg__xingbian",
--   anim_type = "support",
--   events = {fk.EventPhaseStart},
--   can_trigger = function (self, event, target, player, data)
--     return player:hasSkill(self) and player ~= target and target.phase == Player.Play and #H.GetShownCards(player) ~= player:getHandcardNum()
--   end,
--   on_cost = function (self, event, target, player, data)
--     local notshowns = table.filter(player:getCardIds("h"), function (id)
--       return Fk:getCardById(id):getMark(MarkEnum.ShownCards) == 0 end)
--     local pat = ".|.|.|.|.|.|"..table.concat(notshowns, ",")
--     local cards = player.room:askForCard(player, 1, player.hp, false, self.name, true, pat, "#wk_heg__xingbian-show")
--     if #cards > 0 then
--       self.cost_data = {cards = cards, tos = {target.id}}
--       return true
--     end
--   end,
--   on_use = function (self, event, target, player, data)
--     local room = player.room
--     local scards = self.cost_data.cards
--     H.ShowCards(player, scards)
--     scards = U.moveCardsHoldingAreaCheck(room, scards, room.logic:getCurrentEvent().id)
--     if target:isKongcheng() or #scards == 0 then return end
--     local handcards = target:getCardIds("h")
--     local cards = U.askForExchange(player, "wk_heg__xingbian-needhand", "wk_heg__xingbian-wordhand", scards, handcards, self.name)
--     if #cards == 0 then return false end
--     handcards = table.filter(cards, function (id)
--       return table.contains(handcards, id)
--     end)
--     cards = table.filter(cards, function (id)
--       return not table.contains(handcards, id)
--     end)
--     U.swapCards(room, target, target, player, handcards, cards, self.name)
--     local toshowns = table.filter(cards, function (cid)
--       return room:getCardArea(cid) == Card.PlayerHand and room:getCardOwner(cid) == target
--     end)
--     if #toshowns > 0 then
--       H.ShowCards(target, toshowns)
--     end
--   end,
-- }
-- local zhongwang = fk.CreateTriggerSkill{
--   name = "wk_heg__zhongwang",
--   frequency = Skill.Compulsory,
--   events = {fk.AfterCardTargetDeclared},
--   can_trigger = function (self, event, target, player, data)
--     return player:hasSkill(self) and H.compareKingdomWith(player, target) and (data.extra_data or {}).wk_heg__zhongwang and
--       #H.GetShownCards(player) > (H.getKingdomPlayersNum(player.room)[H.getKingdom(player)] or 1) and (player:hasShownSkill(self) or target == player)
--       and data.card.trueName ~= "threaten_emperor" and #player.room:getUseExtraTargets(data) > 0
--   end,
--   on_cost = function (self, event, target, player, data)
--     local room = player.room
--     local targets = room:getUseExtraTargets(data)
--     local tos = room:askForChoosePlayers(target, targets, 1, 1, "#wk_heg__zhongwang-choose", self.name, true)
--     if #tos > 0 then
--       self.cost_data = {tos = tos}
--       return true
--     end
--   end,
--   on_use = function(self, event, target, player, data)
--     table.insert(data.tos, {self.cost_data.tos[1]})
--   end,

--   refresh_events = {fk.PreCardUse},
--   can_refresh = function (self, event, target, player, data)
--     return player == target and not data.card:isVirtual() and data.card:getMark(MarkEnum.ShownCards) > 0
--   end,
--   on_refresh = function (self, event, target, player, data)
--     data.extra_data = data.extra_data or {}
--     data.extra_data.wk_heg__zhongwang = true
--   end,
-- }
-- zhangsunwuji:addSkill(xingbian)
-- zhangsunwuji:addSkill(zhongwang)
-- Fk:loadTranslationTable{
--   ["wk_heg__zhangsunwuji"] = "长孙无忌",
--   ["#wk_heg__zhangsunwuji"] = "",
--   ["designer:wk_heg__zhangsunwuji"] = "小曹神&教父",
--   ["illustrator:wk_heg__zhangsunwuji"] = "",

--   ["wk_heg__xingbian"] = "兴变",
--   [":wk_heg__xingbian"] = "其他角色的出牌阶段开始时，你可以明置至多体力值数张手牌，然后其可以用手牌与你交换其中任意张牌并明置之。",
--   ["wk_heg__zhongwang"] = "众望",
--   [":wk_heg__zhongwang"] = "锁定技，若你的明置牌数大于与你势力相同的角色数，与你势力相同的角色使用明置牌可以额外指定一个目标。",
--   ["#wk_heg__xingbian-show"] = "兴变：你可以明置至多体力值数张手牌",
--   ["wk_heg__xingbian-needhand"] = "对方牌",
--   ["wk_heg__xingbian-wordhand"] = "你的牌",
--   ["#wk_heg__zhongwang-choose"] = "众望：你可以额外选择一名角色为目标",
  
--   ["~wk_heg__zhangsunwuji"] = "",
-- }

-- local taipinggongzhu = General(extension, "wk_heg__taipinggongzhu", "tang", 3, 3, General.Female)
-- local guichong = fk.CreateTriggerSkill{
--   name = "wk_heg__guichong",
--   anim_type = "control",
--   events = {fk.HpRecover},
--   can_trigger = function (self, event, target, player, data)
--     return player:hasSkill(self) and target == player and table.find(player:getCardIds("h"), function (id)
--       return Fk:getCardById(id):getMark(MarkEnum.ShownCards) == 0 end)
--   end,
--   on_cost = function (self, event, target, player, data)
--     local notshowns = table.filter(player:getCardIds("h"), function (id)
--       return Fk:getCardById(id):getMark(MarkEnum.ShownCards) == 0 end)
--     local pat = ".|.|.|.|.|.|"..table.concat(notshowns, ",")
--     local cards = player.room:askForCard(player, 1, 1, false, self.name, true, pat, "#wk_heg__guichong-show")
--     if #cards > 0 then
--       self.cost_data = cards
--       return true
--     end
--   end,
--   on_use = function (self, event, target, player, data)
--     local room = player.room
--     H.ShowCards(player, self.cost_data)
--     local targets = table.filter(room.alive_players, function (p)
--       return p:canMoveCardsInBoardTo(player, "e")
--     end)
--     if #targets > 0 then
--       local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#wk_heg__guichong-move", self.name, false)
--       if #tos > 0 then
--         room:askForMoveCardInBoard(player, room:getPlayerById(tos[1]), player, self.name, "e", room:getPlayerById(tos[1]))
--       end
--     end
--   end,
-- }
-- local fuchao = fk.CreateTriggerSkill{
--   name = "wk_heg__fuchao",
--   anim_type = "offensive",
--   events = {fk.EventPhaseStart},
--   can_trigger = function (self, event, target, player, data)
--     return player:hasSkill(self) and player ~= target and target.phase == Player.Finish and not target.dead and
--       not player:isNude()
--   end,
--   on_cost = function (self, event, target, player, data)
--     local ecards = table.filter(player:getCardIds("he"), function (cid)
--       return Fk:getCardById(cid).type == Card.TypeEquip and player:canMoveCardInBoardTo(target, cid)
--     end)
--     local pat = ".|.|.|.|.|.|"..table.concat(ecards, ",")
--     local cards = player.room:askForCard(player, 1, 1, true, self.name, true, pat, "#wk_heg__fuchao-put::"..target.id)
--     if #cards > 0 then
--       self.cost_data = {cards = cards, tos = {target.id}}
--       return true
--     end
--   end,
--   on_use = function (self, event, target, player, data)
--     local room = player.room
--     room:moveCardIntoEquip(target,self.cost_data.cards, self.name, false, player)
--     local force = #H.GetShownCards(player) == player:getHandcardNum()
--     if player.dead or target.dead then return end
--     if not H.askCommandTo(player, target, self.name, force) then
--       if not target:isKongcheng() then
--         local card = room:askForCardChosen(player, target, "h", self.name)
--         local count = #(room.logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable)
--         room:obtainCard(player, card, true, fk.ReasonPrey, player.id, self.name)
--         local e = room.logic.event_recorder[GameEvent.MoveCards][count + 1]
--         if e and #e.data > 0 then
--           local toshowns = {}
--           for _, move in ipairs(e.data) do
--             for _, info in ipairs(move.moveInfo) do
--               table.insert(toshowns, info.cardId)
--             end
--           end
--           toshowns = U.moveCardsHoldingAreaCheck(room, toshowns, e.id)
--           H.ShowCards(player, toshowns)
--         end
--       end
--     end
--   end,
-- }
-- taipinggongzhu:addSkill(guichong)
-- taipinggongzhu:addSkill(fuchao)
-- Fk:loadTranslationTable{
--   ["wk_heg__taipinggongzhu"] = "太平公主",
--   ["#wk_heg__taipinggongzhu"] = "",
--   ["designer:wk_heg__taipinggongzhu"] = "静谦",
--   ["illustrator:wk_heg__taipinggongzhu"] = "",

--   ["wk_heg__guichong"] = "贵宠",
--   [":wk_heg__guichong"] = "当你回复体力后，你可以明置一张手牌，然后将场上的一张装备牌移动至你的装备区。",
--   ["wk_heg__fuchao"] = "覆朝",
--   [":wk_heg__fuchao"] = "其他角色的结束阶段，你可以将一张装备牌置入其装备区，然后对其发起“军令”：若其不执行，你获得其一张手牌并明置之；若你的手牌均明置，你以此法发起的“军令”强制执行。",
--   ["#wk_heg__guichong-show"] = "贵宠：你可以明置一张手牌",
--   ["#wk_heg__guichong-move"] = "贵宠：选择一名角色，将其场上的一张装备牌移动至你的装备区",
--   ["#wk_heg__fuchao-put"] = "覆朝：你可将一张装备牌置入 %dest 装备区",

--   ["~wk_heg__taipinggongzhu"] = "",
-- }

local lordlishimin = General(extension, "wk_heg__lordlishimin", "tang", 4)
lordlishimin.hidden = true
lordlishimin:addSkills{"wk_heg__zhenguan", "wk_heg__wanning", "wk_heg__yonggu"}
-- H.lordGenerals["hs__n_lishimin"] = "wk_heg__lordlishimin"
Fk:loadTranslationTable{
  ["wk_heg__lordlishimin"] = "君李世民",
  ["#wk_heg__lordlishimin"] = "",
  ["designer:wk_heg__lordlishimin"] = "",
  ["illustrator:ld__lordlishimin"] = "",

  ["~wk_heg__lordlishimin"] = "",
}


-- local extension_card = Package("tang_ld_cards", Package.CardPack)
-- extension_card.extensionName = "new_heg"
-- extension_card.game_modes_whitelist = { 'mul_heg_mode' }

-- local guotaiminanSkill = fk.CreateActiveSkill{
--   name = "wk_heg__guotaiminan_skill",
--   prompt = "#wk_heg__guotaiminan_skill",
--   target_num = 1,
--   mod_target_filter = function(self, to_select, selected, player)
--     local target = Fk:currentRoom():getPlayerById(to_select)
--     return H.compareKingdomWith(target, player)
--   end,
--   target_filter = Util.TargetFilter,
--   can_use = Util.CanUse,
--   on_effect = function(self, room, effect)
--     local player = room:getPlayerById(effect.from)
--     local target = room:getPlayerById(effect.to)
--     local e = player.room.logic:getCurrentEvent()
--     while e do
--       if e.event == GameEvent.UseCard then
--         local use = e.data[1]
--         if use.card.name == "wk_heg__guotaiminan" then
--           use.extra_data = use.extra_data or {}
--           use.extra_data.wk_heg__guotaiminaneffect = true
--           break
--         end
--       end
--       e = e.parent
--     end
--     if target.dead then return end
--     room:recover{
--       who = target,
--       recoverBy = player,
--       card = effect.card,
--       num = 1,
--       skillName = self.name
--     }
--     if target.dead then return end
--     target:drawCards(1, "wk_heg__guotaiminan")
--   end,
--   on_action = function (self, room, use, finished)
--     if finished then
--       local player = room:getPlayerById(use.from)
--       if not player.dead and not (use.extra_data and use.extra_data.wk_heg__guotaiminaneffect) then
--         player:turnOver()
--       end
--     end
--   end
-- }
-- local guotaiminan = fk.CreateTrickCard{
--   name = "wk_heg__guotaiminan",
--   skill = guotaiminanSkill,
--   suit = Card.Diamond,
--   number = 1,
-- }
-- --卡牌替换，耦合的，原方法只能替换某牌名的全部牌，见nos_new_heg.lua
-- extension_card:addCard(guotaiminan)
-- Fk:loadTranslationTable{
--   ["tang_ld_cards"] = "鼎业积功卡牌",
--   ["wk_heg__guotaiminan"] = "国泰民安",
--   ["wk_heg__guotaiminan_skill"] = "国泰民安",
--   [":wk_heg__guotaiminan"] = "锦囊牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名与你势力相同的角色<br/><b>效果</b>：目标角色回复1点体力并摸一张牌，若此牌未生效，你叠置。",
--   ["#wk_heg__guotaiminan_skill"] = "选择势力与你相同的一名角色，其回复1点体力并摸一张牌，若此牌未生效，你叠置",
-- }

return extension
